﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Tycho.Lexer;
using Tycho.Parser.Peg;
using Tycho.Parser.Tokens;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class ChoiceProductionSpecification {
        [Test]
        public void ParseShouldReturnTermOfSuccessfulParse () {
            var choice = new ChoiceProduction<object> (new IdentifierTerminal<object> (), new IntegerTerminal<object> ());

            Token [] tokens = NativeLexer.Lex ("a").ToArray ();

            var result = choice.Parse (tokens, 0, null);

            Assert.IsNotNull (result);
            Assert.AreEqual (1, result.Index);
            Assert.AreEqual ("a", ((IdentifierTerm) result.Term).Name);
        }

        [Test]
        public void ParseShouldReturnNullIfNoProductionParses () {
            var choice = new ChoiceProduction<object> (new KeywordTerminal<object> ("="), new IntegerTerminal<object> ());

            Token [] tokens = NativeLexer.Lex ("a").ToArray ();

            var result = choice.Parse (tokens, 0, null);

            Assert.IsNull (result);
        }
    }
}